//
//  UIButton+Extension.swift
//  Weibo
//
//  Created by mac on 16/1/15.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(title: String, color: UIColor, fontSize: CGFloat) {
    
        self.init()
        self.setTitleColor(color, forState: .Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(16)
        self.setTitle(title, forState: .Normal)
        let bacImage = UIImage(named: "common_button_white_disable")!
        
        let tempWidth = bacImage.size.width * CGFloat(0.5)
        let tempHeight = bacImage.size.height * CGFloat(0.5)
        
        self.setBackgroundImage(bacImage.stretchableImageWithLeftCapWidth( Int(tempWidth), topCapHeight: Int(tempHeight)), forState: .Normal)
        
    }
    
    convenience init(backImageName: String, btnImageName: String) {
        self.init()
        
        let highlightedBacImageName = backImageName + "_highlighted"
        let highlightedBtnImageName = btnImageName + "_highlighted"
        
        self.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        self.setBackgroundImage(UIImage(named: highlightedBacImageName), forState: .Highlighted)
        
        self.setImage(UIImage(named:btnImageName ), forState: .Normal)
        self.setImage(UIImage(named: highlightedBtnImageName), forState: .Highlighted)
        
        self.sizeToFit()
    }

}
